package cn.echo.ecc.web.controller;

import cn.echo.ecc.dto.SmsCodeDto;
import cn.echo.ecc.result.JSONResult;
import cn.echo.ecc.service.IVerifyCodeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/verifycode")
public class VerifyCodeController {

    @Autowired
    private IVerifyCodeService verifyCodeService;

    /**
     * 获取图形验证码
     * @param key
     * @return
     */
    @RequestMapping(value="/imageCode/{key}",method= RequestMethod.GET)
    public JSONResult imageVerifyCode(@PathVariable("key") String key) {
        // 1.调用方法获取图形验证码
        String base64Str = verifyCodeService.getImageCode(key);
        // 2.将base64的字符串返回给前端
        return JSONResult.success(base64Str);
    }

    @RequestMapping(value="/sendSmsCode",method= RequestMethod.POST)
    public JSONResult sendSmsCode(@RequestBody SmsCodeDto smsCodeDto) {
        // 1.调用方法获取手机验证码
        verifyCodeService.sendSmsCode(smsCodeDto);
        // 2.响应结果给前端
        return JSONResult.success();
    }



}
